/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 *
 * @author dloaiza
 */
@Entity
@Table(name = "TAB_TIPO_DOCUMENTO")
@NamedQueries({
    @NamedQuery(name = "TipoDocumento.findAll", query = "SELECT t FROM TipoDocumento t")})
public class TipoDocumento implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @Column(name = "ID_TIPO_DOCUMENTO", nullable = false, precision = 20, scale = 0)
    @TableGenerator(name = "tipoD",
            table = "TBL_SQ",
            pkColumnName = "GEN_KEY",
            valueColumnName = "GEN_VALUE",
            pkColumnValue = "FAC_CON",
            initialValue = 0,
            allocationSize = 1)
    @GeneratedValue(strategy=GenerationType.TABLE, generator="tipoD")
    private BigDecimal idTipoDocumento;
    @Column(name = "DSTIPO_DOCUMENTO", length = 50)
    private String dstipoDocumento;
    @OneToMany(mappedBy = "nmidTipoDocumento", fetch = FetchType.LAZY)
    private List<Contacto> contactoList;
    @OneToMany(mappedBy = "dsidTipoDocumento", fetch = FetchType.LAZY)
    private List<Usuario> usuarioList;

    public TipoDocumento() {
    }

    public TipoDocumento(BigDecimal idTipoDocumento) {
        this.idTipoDocumento = idTipoDocumento;
    }

    public BigDecimal getIdTipoDocumento() {
        return idTipoDocumento;
    }

    public void setIdTipoDocumento(BigDecimal idTipoDocumento) {
        this.idTipoDocumento = idTipoDocumento;
    }

    public String getDstipoDocumento() {
        return dstipoDocumento;
    }

    public void setDstipoDocumento(String dstipoDocumento) {
        this.dstipoDocumento = dstipoDocumento;
    }

    public List<Contacto> getContactoList() {
        return contactoList;
    }

    public void setContactoList(List<Contacto> contactoList) {
        this.contactoList = contactoList;
    }

    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idTipoDocumento != null ? idTipoDocumento.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TipoDocumento)) {
            return false;
        }
        TipoDocumento other = (TipoDocumento) object;
        if ((this.idTipoDocumento == null && other.idTipoDocumento != null) || (this.idTipoDocumento != null && !this.idTipoDocumento.equals(other.idTipoDocumento))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.alexstarkbd.jpa.entities.TipoDocumento[ idTipoDocumento=" + idTipoDocumento + " ]";
    }
    
    @PostLoad
    public void fixIt(){
        this.usuarioList = new ArrayList<Usuario>(this.usuarioList);
        this.contactoList = new ArrayList<Contacto>(this.contactoList);
    }
}
